/**************************提示：只允许修改开发区域，其他区域会被覆盖！********************************/
mod.definePage("extend/cp/bc/js/BizAccountBill_Edit_Open001",function(waf){
    //@beginUseModule
    var bizCollBillBase = mod.useSync("cp/bc/js/bizCollBillBase");
    var promptExpenseType = mod.useSync("cp/bc/js/promptExpenseType");
    var BizAccountBill_Edit_Open = mod.useSync("cp/bc/js/BizAccountBill_Edit_Open");
    var promptSpecial_Project002 = mod.useSync("extend/custom/ct/js/promptSpecial_Project002");
    //@endUseModule
    var _public = {},_private = {},me=_self;
    //@beginPublic
    waf.extend(_public,{
        //控件事件描述:
        costCenterChange:function(event,value){
             return _private.costCenterChange(event,value);
        }
	    ,
        //控件事件描述:
        projectChange:function(event,value){
             return _private.projectChange(event,value);
        }
	    ,
        //控件事件描述:
        quarterageChange:function(event,value){
             return _private.quarterageChange(event,value);
        }
	    ,
        //控件事件描述:
        boardWagesChange:function(event,value){
             return _private.boardWagesChange(event,value);
        }
	    ,
        //控件事件描述:
        otherExpensesChange:function(event,value){
             return _private.otherExpensesChange(event,value);
        }
	    ,
        //控件事件描述:
        projectOnchange:function(event,value){
             return _private.projectOnchange(event,value);
        }
	    ,
        //控件事件描述:
        extEditGridRowAdd:function(rowid,rowdata,rowelem){
             return _private.extEditGridRowAdd(rowid,rowdata,rowelem);
        }
	    ,
        //控件事件描述:
        payModeChange:function(event,value){
             return _private.payModeChange(event,value);
        }
	    ,
        //页面事件描述:分录控件隐藏/显示
        entriesControlChange:function(e){
             return _private.entriesControlChange(e);
        }
	    ,
        //页面事件描述:
        setCustomF7:function(e){
             return _private.setCustomF7(e);
        }
	    ,
        //页面函数描述:分录金额合计
        entryMoenyChange:function(event,value){
             return _private.entryMoenyChange(event,value);
        }
	    ,
        //页面函数描述:获取会议费标准
        getMeetingCost:function(){
             return _private.getMeetingCost();
        }
    });
    _self.subscribeEvent("pageOnLoadEvent",_public.entriesControlChange,"after");
    _self.subscribeEvent("fieldOnLoadEvent",_public.setCustomF7,"after");
    //@endPublic
    //@beginTemplateFunctions

    //@endTemplateFunctions

    /**************************开发区域开始**********************************************/
    //@beginPrivate
    waf.extend(_private,{
    	projectOnchange:function(event,value){
          var editGridDom = waf("#entries");
          	 if(value.current.name.l2=="会议费"){
               editGridDom.wafGrid("showColumn", ["meetingCost", "personNumber","dayNumber","quarterage","boardWages","otherExpenses"]);
               editGridDom.lockColumn("amountOri");
               
               var rowid = editGridDom.wafGrid("getSelectedRow");
               editGridDom.wafGrid("setCell", rowid, "quarterage",0);
               editGridDom.wafGrid("setCell", rowid, "boardWages",0);
               editGridDom.wafGrid("setCell", rowid, "otherExpenses",0);
             }else{
               editGridDom.wafGrid("hideColumn", ["meetingCost", "personNumber","dayNumber","quarterage","boardWages","otherExpenses"]);
               editGridDom.unLockColumn("amountOri");
             }
        }
	    ,
        quarterageChange:function(event,value){
           _private.entryMoenyChange(event,value);
        }
	    ,
        boardWagesChange:function(event,value){
            _private.entryMoenyChange(event,value);
        }
	    ,
        otherExpensesChange:function(event,value){
            _private.entryMoenyChange(event,value);
        }
	    ,
        costCenterChange:function(event,value){
            var editGridDom = waf("#entries");
    		  var rowid = editGridDom.wafGrid("getSelectedRow");
           editGridDom.wafGrid('setCellEditorAllConfig', "project","filteritem","admin.id='"+value.current.id+"'  or  admin.id = null","promptGrid",rowid); 
        }
	    ,
        entriesControlChange:function(e){
            var editGridDom = waf("#entries");
           var getDataIDs = editGridDom.wafGrid("getDataIDs");
            for(var i=0;i<getDataIDs.length;i++){
              var rowid=getDataIDs[i];
               var costCenter = editGridDom.wafGrid("getCell", rowid, "costCenter");
               editGridDom.wafGrid('setCellEditorAllConfig', "project","filteritem","admin.id='"+costCenter.id+"'  or  admin.id = null","promptGrid",rowid); 
              var project = editGridDom.wafGrid("getCell", rowid, "project");
              editGridDom.wafGrid("setCell", rowid, "ext_gridCol0",project);
            }
         
           var editGridCollection = waf("#editGrid_collection");
           var collectionIds = editGridCollection.wafGrid("getDataIDs");
            for(var i=0;i<collectionIds.length;i++){
              var rowid=collectionIds[i];
              var payMode = editGridCollection.wafGrid("getCell", rowid, "payMode");
               if(payMode.name.l2=="转账到公司"){
               		editGridCollection.wafGrid('changeCellConfig', rowid, "identityCard", {"editable":false});
               }
            }
          
          _private.getMeetingCost();
          
          var rowid = editGridDom.wafGrid("getRowId",1);
			  if(rowid!=null){
            var project = editGridDom.wafGrid("getCell", rowid, "project");
            if(project!=null&&project!=""&&project.name.l2=="会议费"){
              editGridDom.wafGrid("showColumn", ["meetingCost", "personNumber","dayNumber","quarterage","boardWages","otherExpenses"]);
              editGridDom.lockColumn("amountOri");
            }else{
              editGridDom.wafGrid("hideColumn", ["meetingCost", "personNumber","dayNumber","quarterage","boardWages","otherExpenses"]);
              editGridDom.unLockColumn("amountOri");
            }
          }
        }
	    ,
        entryMoenyChange:function(event,value){
           var editGridDom = waf("#entries");
    		 var rowid = editGridDom.wafGrid("getSelectedRow");
            var rowIndex= editGridDom.wafGrid("getRowIndex",rowid);
             var rowObj = editGridDom.wafGrid("getRowRealData",rowid);
    		 var amountOri = rowObj.quarterage+rowObj.boardWages+rowObj.otherExpenses;
             var oldValue=editGridDom.wafGrid("getCell", rowid, "amountOriWithoutTax");
             editGridDom.wafGrid("setCell", rowid, "amountOriWithoutTax",amountOri);
            BizAccountBill_Edit_Open.editGridCellSave(rowid,"amountOriWithoutTax",amountOri,rowIndex,17,oldValue);
        }
	    ,
        getMeetingCost:function(){
           var editGridDom = waf("#entries");
          var getDataIDs = editGridDom.wafGrid("getDataIDs");
          for(var i=0;i<getDataIDs.length;i++){
            var id=getDataIDs[i];
            var meetingCost = editGridDom.wafGrid("getCell", id, "meetingCost");
            var option=_self.getOptionFromArguments(arguments);
            if(meetingCost!=null&&meetingCost!=""){
              option.action="MeetingCostAction";
              option.data={"id":meetingCost.id};
               option.async=false;
              option.success=function(data){
                  editGridDom.wafGrid("setCell", id, "meetingCost",data);
              }
          		waf.doPost(option);
            }
          }
        }
    	,
		payModeChange:function(event,value){
            var editGridDom = waf("#editGrid_collection");
            var rowid = editGridDom.wafGrid("getSelectedRow");
          	 if(value.current.name.l2=="转账到公司"){
               editGridDom.wafGrid("setCell", rowid, "identityCard",null);
               editGridDom.wafGrid('changeCellConfig', rowid, "identityCard", {"editable":false});
             }else{
               editGridDom.wafGrid('changeCellConfig', rowid, "identityCard", {"editable":true});
               
             }
        }
    	,
		entryCostChange:function(e){
            var editGridDom = waf("#entries");
    		  var rowid = editGridDom.wafGrid("getSelectedRow");
            var costCenter = editGridDom.wafGrid("getCell", rowid, "costCenter");
               editGridDom.wafGrid('setCellEditorAllConfig', "project","filteritem","admin.id='"+costCenter.id+"'  or  admin.id = null","promptGrid",rowid); 
        }
    	,
		extEditGridRowAdd:function(rowid,rowdata,rowelem){
           var editGridDom = waf("#entries");
            var costCenter = editGridDom.wafGrid("getCell", rowid, "costCenter");
               editGridDom.wafGrid('setCellEditorAllConfig', "project","filteritem","admin.id='"+costCenter.id+"'  or  admin.id = null","promptGrid",rowid); 
        }
    	,
		setCustomF7:function(e){
           $("#entries").wafGrid("hideColumn","project",true);
          var cols = waf("#entries").wafGrid("getAllColumn");
					for (var i = 0; i < cols.length; i++) {	//遍历列
						var col = cols[i];

						if (col.id == "ext_gridCol0" ) {				
								//获取配置界面的自定义F7的url的值
						    	var url = col.editoptions.subTagJson.url;
						
								//如果是customF7开头（随便写，自定义的）
								if (url.indexOf("customF7") >= 0) {
									//修改列的编辑属性subWidgetName的值为customF7后面
									col.editoptions.subWidgetName = url.slice(url.indexOf('=') + 1);
								}
							}
					}
        }
    	,
		projectChange:function(event,value){
           var curent = value.current;
          var editGridDom = waf("#entries");
          var rowid = editGridDom.wafGrid("getSelectedRow");
       	   editGridDom.wafGrid("setCell", rowid, "project",curent);
          BizAccountBill_Edit_Open.entryProjectChange(rowid, curent);
          _private.projectOnchange(event, value);
        }
    });//@endPrivate
    /**************************开发区域结束**********************************************/
    return _public;
});
